'use strict';

const conn = require('../../../libs/Conn');
const _ = require('underscore');
const util = require('../../../libs/Utils');

module.exports = async function (params) {
    try {
        let oldPassword = util.encrypt(params.oldPassword);
        let checkSql = `SELECT user_id FROM  user_file uf WHERE uf.user_id = '${params.user_id}' AND password='${oldPassword}'`;
        let userData = await conn(checkSql);
        if (userData.shift()) {
            let newPassword = util.encrypt(params.newPassword);
            let updateSql = `UPDATE user_file  SET password = '${newPassword}' WHERE user_id='${params.user_id}'`;
            await conn(updateSql);
            return {success: true};
        } else {
            return {success: false, message: '请输入正确的旧密码'};
        }
    } catch (e) {
        return {success: false, message: e};
    }
};